/**
 * 用户信息配置类.可以往里边加入其他配置信息.
 */
import Config from "./Config";
import {getConfig} from "./ConfigHelper";
import Common from "../../framework/utils/Common";

class UserProfile extends Config {
    public userId: string = null;
    public name: string = null;
    public token: string = null;
    public avatar: string = null;
    public deviceID: string = "";
    public password: string = "";
    public openid: string = "";

    // 如果有三方用户绑定逻辑，则需要存储绑定关系数据。
    public thirdInfo: any = {
        // 第三方帐号会话标识。
        session: null,
        avatar: "",
        deviceid: "",
        gender: 1,
        mac: "",
        nickname: "",
        regTime: "",
        token: "",
        userid: 0,
    };

    constructor() {
        super("user");
    }

    public setInfo(uId: string, name: string, avatar: string, token: string) {
        this.userId = uId;
        this.name = name;
        this.avatar = avatar;
        this.token = token;
        this.save();
        cc.log("保存玩家信息:", this.userId);
    }

    public updateThirdInfo(info: any) {
        Common.assign(userProfile.thirdInfo, info);
        userProfile.save();
    }
}

export const userProfile: UserProfile = getConfig(UserProfile);
